<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
class IndexController extends Controller
{
    //
    public function index()
    {
    	$data = DB::table('control')->get();
    	$allprice = null;
    	$varnum = null;
    	foreach ($data as $k => $v) {
    		// 总收入=商品单价*售出总量累加
    		$allprice += ($v->goodsprice)*($v->allnum);
    		// 售出总件
    		$varnum += $v->allnum; 
    	}
    	$da = DB::table('goods')->get();
    	$allnum = null;
    	$resstock = null;
    	foreach ($da as $key => $value) {
    		// 总库存
    		$allnum += $value->stock;
    		// 剩余总库存
    		$resstock += $value->varstock;
    	}
    	return view("admin.index",['data'=>$data,'allprice'=>$allprice,'varnum'=>$varnum,'allnum'=>$allnum,'resstock'=>$resstock]);
    }
}
